package bjut.zrpc.core.optimization.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Author: zhuzhiming
 * @Date: 2022/6/24 0:22
 */
@AllArgsConstructor
@Getter
public enum ZRpcSerializerEnum {

    HESSIAN((byte) 0x01, "hessian"),
    PROTOSTUFF((byte) 0x02, "protostuff"),
    KRYO((byte) 0x03, "kryo");

    private final byte codec;
    private final String serializerName;

    public static String getSerializationName(byte codec) {

        for (ZRpcSerializerEnum type : ZRpcSerializerEnum.values()) {
            if (type.codec == codec) {
                return type.getSerializerName();
            }
        }
        return null;
    }

    public static byte getSerializationType(String codeName) {

        for (ZRpcSerializerEnum type : ZRpcSerializerEnum.values()) {
            if (type.getSerializerName().equals(codeName)) {
                return type.getCodec();
            }
        }
        return (byte) 0x01;
    }

}
